﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using NaireSystem.Api.Dto;
using NaireSystem.Api.VO;
using NaireSystem.Datas;
using NaireSystem.DBEntity;
using TYBase;

namespace NaireSystem.Api
{
    public class UserApi
    {
        public static R<UserVO> Login(string userId, string password)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/login/login")
                    .SetData(new { userId, password }.JsonAsString())
                    .SetPost().Excute(out string data))
                {
                    return R<UserVO>.Fail(data);
                }
                return data.AsModel<R<UserVO>>();
            }
            catch (Exception ex)
            {
                return R<UserVO>.Fail("登录失败!", ex);
            }
        }

        internal static R<bool> Edit(Tbl_UserInfo userInfo)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/user/editUserInfo")
                    .SetData(userInfo.JsonAsString())
                    .SetPost().Excute(out string data))
                {
                    return R<bool>.Fail(data);
                }
                return data.AsModel<R<bool>>();
            }
            catch (Exception ex)
            {
                return R<bool>.Fail("编辑用户信息失败!!", ex);
            }
        }

        public class UserInfoWithDept
        {
            public Public_sysuser su { get; set; }
            public Tbl_UserInfo ui { get; set; }
            public Public_userOffice uo { get; set; }
            public Public_office office { get; set; }
        }
        public static RPage<UserInfoVo> GetUserInfoList(PageInfo pageInfo, UserInfoVo userInfo)
        {
            //getUserInfoList
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/user/getUserInfoList?{pageInfo.AsQueryData()}&{userInfo.AsQueryData()}")
                    .SetGet().Excute(out string data))
                {
                    return RPage<UserInfoVo>.Fail(data);
                }
                return data.AsModel<RPage<UserInfoVo>>();
            }
            catch (Exception ex)
            {
                return RPage<UserInfoVo>.Fail("获取用户信息失败!", ex);
            }
        }
    }
}
